﻿using SharpSoft.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SignApp
{
    /// <summary>
    /// DevicePage.xaml 的交互逻辑
    /// </summary>
    public partial class DevicePage : Page
    {
        public DevicePage()
        {
            InitializeComponent();
            this.Loaded += DevicePage_Loaded;
        }

        private async void DevicePage_Loaded(object sender, RoutedEventArgs e)
        {
            var wait = await this.WaitAsync("获取设备信息...");
            try
            {
                txt.Text = await Task.Run(delegate
                           {
                               var cpuid = SharpSoft.OS.Windows.GetCPUID();
                               var uuid = SharpSoft.OS.Windows.GetBaseBoardUUID();
                               var disk = SharpSoft.OS.Windows.GetHardDiskSerialNumber();
                               var md5 = SharpSoft.Security.MD5Hash($"{cpuid}{uuid}{disk}");
                               return md5;
                           });
            }
            catch (Exception _)
            {
                await this.SampleAsync("获取设备信息失败。", ThemeColor.Error);
            }
            finally
            {
                wait.Close();
            }

        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Clipboard.SetDataObject(txt.Text);
                await this.ToastAsync("已复制", txt.Text, SharpSoft.WPF.Masks.ToastTemplate.ToastType.Info, TimeSpan.FromSeconds(3));
            }
            catch (Exception _)
            {
                await this.SampleAsync("复制失败，请手工复制。", ThemeColor.Error);
            }

        }
    }
}
